/**
 * @class yijs.Preload
 * @fileOverview 预加载动画
 * @author 谢文浩
 * @email mohaiguyan12@126.com
 * @version 0.11
 * @date 2010-04-15
 */
yijs.Preload = function(applyTo){
	this.defaultMSg = "";
	this.applyTo = applyTo || ".yijs-preload";
	this.$applyTo = null;
}
yijs.Preload.prototype = {
	/**
	 * 显示预加载层
	 */
	show : function(msg){
		if (this.$applyTo == null) {
			this.create();
			this.center();
		}
		var $preload = this.$applyTo;
		this.msg(msg || this.defaultMSg || "");
	    $preload.css("display") == "none" && $preload.stop().fadeIn("fast");	
	},
	/**
	 * 创建预加载层
	 */	
	create : function(){
		var _that = this;
		var html = "<div id='PRE_LOAD' class='yijs-preload'>"+
		                "<div id='PRE_LOAD_IMG' /><div id='PRE_LOAD_MSG'></div>"+
				   "</div>";	   
		$("body").append(html);  
		this.$applyTo = $(this.applyTo); 
		this.$applyTo.click(function(){
			_that.hide(0);
		});		
	},
	/**
	 * 隐藏预加载层
	 */		
	hide : function(delayTimer,callback){
		if (this.$applyTo.size() > 0) {
			delayTimer && this.$applyTo.delay(delayTimer).fadeOut("fast",function(){callback && callback.call(this)}) || $("#PRE_LOAD").fadeOut("fast");
		}	
	},
	/**
	 * 设置预加载层显示信息
	 */		
	msg : function(message){
		$("#PRE_LOAD_MSG").html(message);
	},
	/**
	 * 居中预加载层
	 */		
	center : function(){
		var width = this.$applyTo.innerWidth();
		var height = this.$applyTo.innerHeight();
		var marginLeft = width/2;
		var marginTop =  height/2;
		var bodyWidth = $("body").width();
		var bodyHeight = $("body").height();
		var w = Math.floor(bodyWidth/2 - marginLeft);
		var h = Math.floor(bodyHeight/2 - marginTop);
		this.$applyTo.css({"top":h,"left":w});
	},
	ajaxing : false	
}
